﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Padelcenter.Common;
using Padelcenter.BusinessLogic.Get;

namespace Padelcenter.BusinessLogic
{
    public class MonedaBS
    {
        #region Private Vars

        private bool _Disposed = false;
        
        #endregion

        #region Constructor

         public MonedaBS()
         {            
         }

        ~MonedaBS()
		{
			this.Dispose(false);
        }
        
        #endregion
        
        #region Public Methods

        public List<Moneda> MonedaSelect(Moneda moneda)
        {
            GetMoneda oGetMoneda = null;

            try
            {
                if (moneda == null)
                {
                    moneda = new Moneda();
                }
                oGetMoneda = new GetMoneda();
                oGetMoneda.Moneda = moneda;

                return oGetMoneda.MonedaList();
            }
            catch (Exception e)
            {
                // Common Exception
                throw (new Exception("MonedaBS.MonedaSelect: " + e.Message.ToString()));
            }
            finally
            {
                if (oGetMoneda != null)
                    oGetMoneda.Dispose();
                oGetMoneda = null;
            }
        }

        public int MonedaUpdate(int idMoneda, string descripcion, double cotizacion, string simbolo, bool activo)
        {
            Moneda oMoneda = null;
            Update.UpdateMoneda oUpdateMoneda = null;
            try
            {
                oMoneda = new Moneda();
                oMoneda.IdMoneda = idMoneda;
                oMoneda.Descripcion = descripcion;
                oMoneda.Cotizacion = cotizacion;
                oMoneda.Simbolo = simbolo;
                oMoneda.Activo = activo;

                oUpdateMoneda = new Update.UpdateMoneda();
                oUpdateMoneda.Moneda = oMoneda;
                oUpdateMoneda.Update();
                
                return oUpdateMoneda.Resultado;
            }
            catch (Exception e)
            {
                // Common Exception
                throw (new Exception("MonedaBS.MonedaUpdate: " + e.Message.ToString()));
            }
            finally
            {
                if (oMoneda != null)
                    oMoneda.Dispose();
                oMoneda = null; 

                oUpdateMoneda = null;
            }
        }
        #endregion

        #region IDisposable Members

        public void Dispose()
        {
            this.Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposable)
        {
            if (!this._Disposed)
            {
                if (disposable)
                {
                    ReleaseManagedResources();
                }
                ReleaseUnmanagedResources();
            }
            _Disposed = true;
        }

        /// Release unmanaged resources
        protected virtual void ReleaseUnmanagedResources()
        {
        }
        
        /// Release managed resources		
        protected virtual void ReleaseManagedResources()
        {
        }

        #endregion
    }
}
